﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CoreLibrary.People;
using CoreLibrary.Objects;
using CoreLibrary.Utility;
using FluentAssertions;
using CoreLibrary;

namespace CoreGameplayUnitTest
{
    [TestClass]
    public class UnitTestPeopleGiveItem
    {
        Person p1 = new Person() { Name = "Test" };
        Bond b;
        Person p2 = new Person() { Name = "Test2" };

        [TestInitialize]
        public void Initialize()
        {
            b = new Bond(p1, p2);
            p1.SetBond(p2, b);
        }

        [TestMethod]
        public void DyanmicCheckShouldReturnTrue()
        {
            dynamic d = new Item() { Name = "Test" };
            bool returnVal = DynamicHelper.HasPropertyValue(d, "Name", "Test");
            returnVal.Should().BeTrue();
        }

        [TestMethod]
        public void People_ShouldGiveItem()
        {
            Item i = new Item();
            p1.AquireItem(i);
            p1.GiveItem(p2, i);

            p1.ItemList.Should().NotContain(i);
            p2.ItemList.Should().Contain(i);
        }

        [TestMethod]
        public void People_Bonds_ShouldBeSet()
        {
            p1.Bonds.ContainsKey(p2.Name).Should().BeTrue();
            p1.Bonds.ContainsValue(b).Should().BeTrue();
            p2.Bonds.ContainsKey(p1.Name).Should().BeTrue();
            p2.Bonds.ContainsValue(b).Should().BeTrue();
        }

        [TestMethod]
        public void People_GiveLikedItemCategory_ShouldIncreaseBond()
        {
            Item i = new Item() { Category = ItemCategory.Book };
            p2.LikeNotLike.AddProperty(TierLevel.Good, typeof(Item), PropertyHelper<ItemCategory>.GetPropertyName(() => i.Category), i.Category);

            p1.AquireItem(i);
            p1.GiveItem(p2, i);

            b.BondStrength.Should().Be(1);
        }

        [TestMethod]
        public void People_GiveDislikedItemCategory_ShouldDecreaseBond()
        {
            Item i = new Item() { Category = ItemCategory.Book };
            p2.LikeNotLike.AddProperty(TierLevel.Bad, typeof(Item), PropertyHelper<ItemCategory>.GetPropertyName(() => i.Category), i.Category);

            p1.AquireItem(i);
            p1.GiveItem(p2, i);

            b.BondStrength.Should().Be(-1);
        }

        [TestMethod]
        public void TierAdjustment_AdjustNeutralToPositive_ShouldReturnPositive()
        {
            var initial = TierLevel.Neutral;
            var adjustTier = TierLevelHelper.AdjustTier(initial, TierLevel.Good);
            adjustTier.Should().Be(TierLevel.Good);
        }

        [TestMethod]
        public void TierAdjustment_AdjustGreatToGreat_ShouldReturnGreat()
        {
            var initial = TierLevel.Great;
            var adjustTier = TierLevelHelper.AdjustTier(initial, TierLevel.Great);
            adjustTier.Should().Be(TierLevel.Great);
        }

        [TestMethod]
        public void TierAdjustment_AdjustGreatToTerrible_ShouldReturnNeutral()
        {
            var initial = TierLevel.Great;
            var adjustTier = TierLevelHelper.AdjustTier(initial, TierLevel.Terrible);
            adjustTier.Should().Be(TierLevel.Neutral);
        }

        [TestMethod]
        public void PeopleTempTest()
        {
            PeopleTemp temp = new PeopleTemp();

            Bond b = new Bond(temp.people[0], temp.people[3]);
            temp.people[0].SetBond(temp.people[3], b);

            Bond b1 = new Bond(temp.people[1], temp.people[3]);
            temp.people[1].SetBond(temp.people[3], b1);

            Bond b2 = new Bond(temp.people[2], temp.people[3]);
            temp.people[2].SetBond(temp.people[3], b2);

            string s = temp.people[3].Bonds.Values.OrderByDescending(
                p => p.BondStrength).First().People.Where(
                q => !q.Equals(temp.people[3])).First().Name;
        }
    }
}
